<template>
  <div class="check-info">
    <div v-if="list && list.length" v-for="item of list" class="item">
      <split-title text="排查情况" />
      <descriptions :columns="columns.slice(0, 5)" :data-source="item" :label-style="{ opacity: 1 }" />
      <div v-for="(zzItem, zzIndex) of item.zzList">
        <split-title :text="`整治情况${zzIndex + 1}`" />
        <descriptions :columns="columns.slice(5, 10)" :data-source="zzItem" :label-style="{ opacity: 1 }" />
      </div>
      <div v-for="(lookBackItem, lookBackIndex) of item.lookBackList">
        <split-title :text="`回头看情况${lookBackIndex + 1}`" />
        <descriptions :columns="columns.slice(-5)" :data-source="lookBackItem" :label-style="{ opacity: 1 }" />
      </div>
    </div>
    <a-empty v-else />
  </div>
</template>

<script>
import SplitTitle from '@gis/lib/components/splitter/split-title.vue';
import { getEnumText } from '@gis/lib/enums/index.js';
import {
  selfBuildHouseLookBackPageList,
  selfBuildHouseRenovatePageList,
  selfBuildHouseTroubleshootingPageList,
} from '@gis/lib/api';
import { handleTableRes } from '@gis/lib/utils/resolver.js';
import get from 'lodash-es/get.js';
import { useDicDataStore } from '@gis/lib/pinia/dicData.js';

export default {
  name: 'check-info',
  components: { SplitTitle },
  props: {
    details: { type: Object, default: () => ({}) },
  },
  data() {
    return {
      list: [
        { is_deformation_damage: 1, specific_damage_location_desc: '', preliminary_judgment: '', time: '', person: '' },
      ],
      columns: [
        { label: '是否发生变形损伤', key: 'is_deformation_damage', format: (v) => getEnumText('whetherOrNot', v) },
        { label: '具体部位', key: 'specific_damage_location_desc' },
        { label: '初步判定', key: 'preliminary_judgment', format: (v) => getEnumText('dangerLevel', v) },
        { label: '排查时间', key: 'time' },
        { label: '排查人', key: 'person' },

        { label: '是否张贴危险通知书', key: 'is_post_danger_notices', format: (v) => getEnumText('whetherOrNot', v) },
        { label: '整治状态', key: 'renovate_status', format: (v) => getEnumText('renovateStatus', v) },
        { label: '管理措施', key: 'management_measures', format: (v) => this.glcsObj[v] },
        { label: '工程措施', key: 'engineering_measures', format: (v) => this.gccsObj[v] },
        { label: '违法建设查处', key: 'investigation_and_punishment' },

        { label: '初判结论是否有误', key: 'is_wrong_preliminary_judgment' },
        {
          label: '最终隐患判定状态',
          key: 'final_hazard_determination_status',
          format: (v) => getEnumText('dangerLevel', v),
        },
        { label: '安全隐患确认情况', key: 'safety_hazards_confirmation' },
        { label: '回头看人员姓名', key: 'look_back_person' },
        { label: '回头看时间', key: 'look_back_time' },
      ],
    };
  },
  computed: {
    // 管理措施
    glcsObj() {
      return this.getDicData('D0155');
    },
    // 工程措施
    gccsObj() {
      return this.getDicData('D0156');
    },
  },
  created() {
    this.getCheckList();
  },
  methods: {
    async getCheckList() {
      const params = Object.assign({}, { house_id: this.details.id, page_size: 999 });
      let { data = [] } = await handleTableRes(selfBuildHouseTroubleshootingPageList(params));
      for (let i = 0; i < data.length; i++) {
        const param = { house_id: data[i].house_id, troubleshooting_id: data[i].id };
        const zzResult = await handleTableRes(selfBuildHouseRenovatePageList(param));
        const lookBack = await handleTableRes(selfBuildHouseLookBackPageList(param));
        data[i].zzList = get(zzResult, 'data', []);
        data[i].lookBackList = get(lookBack, 'data', []);
      }
      // console.log(data, '组合列表');
      this.list = data;
    },
  },
  setup() {
    const { getDicData } = useDicDataStore();
    return { getDicData };
  },
};
</script>

<style lang="less">
.check-info {
  .item {
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
    margin-bottom: 15px;
  }
}
</style>
